//
//  ViewController.m
//  04-音量震动条
//
//  Created by xiaomage on 15/9/29.
//  Copyright (c) 2015年 xiaomage. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UIView *contentV;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    //复制层
    CAReplicatorLayer *repL = [CAReplicatorLayer layer];
    repL.frame = self.contentV.bounds;
    //复制5份出来.
    repL.instanceCount = 6;
    //每一个形变,都是相对于它上一个复制出来的子层开始的.
    repL.instanceTransform = CATransform3DMakeTranslation(40, 0, 0);
    //动画延时执行.
    repL.instanceDelay = 0.5;

    //要设置复制层的颜色,原始层的颜色要设为白色.
    repL.instanceColor = [UIColor redColor].CGColor;
    [self.contentV.layer addSublayer:repL];

    
    //添加音量震动条
    CALayer *layer = [CALayer layer];
    layer.frame = CGRectMake(0, self.contentV.bounds.size.height - 150, 30, 150);
    layer.backgroundColor = [UIColor whiteColor].CGColor;
    
    layer.position = CGPointMake(0, self.contentV.bounds.size.height);
    layer.anchorPoint = CGPointMake(0, 1);

    [repL addSublayer:layer];
    
    //添加动画.(缩放,只缩放y方向).
    //创建动画对象
    CABasicAnimation *anim = [CABasicAnimation animation];
    //设置属性值.
    anim.keyPath = @"transform.scale.y";
    anim.toValue = @0;
    anim.repeatCount = MAXFLOAT;
    anim.duration = 0.5;
    anim.autoreverses = YES;
    [layer addAnimation:anim forKey:nil];
    
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
